package com.fingard.rh.fgmsp.transmanage.manager.query;

import com.fingard.rh.fgmsp.transmanage.dao.query.FingardTransactionsMapper;
import com.fingard.rh.fgmsp.transcommon.dto.transaction.FingardTransactionsPO;
import com.fingard.rh.fgmsp.transcommon.dto.transaction.FingardTransactionsDTO;
import com.fingard.rh.fgmsp.transmanage.dto.query.FingardTransactionsParam;
import com.fingard.rh.fgmsp.transmanage.dto.query.CountsDTO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import com.fingard.rh.fgmsp.common.exception.MspDbException;

/**
 * @author lincc
 * @version 1.0 2019/03/29
 */
@Component
public class FingardTransactionsManager {

    @Autowired
    private FingardTransactionsMapper fingardTransactionsMapper;

    public PageInfo<FingardTransactionsPO> listPage(FingardTransactionsParam param){
        PageHelper.startPage(param.getPageNum(), param.getPageSize(), param.getOrderBy());
        return new PageInfo<>(fingardTransactionsMapper.queryBySelective(param));
    }

    public List<FingardTransactionsPO> queryBySelective(FingardTransactionsParam fingardTransactions) {
        return fingardTransactionsMapper.queryBySelective(fingardTransactions);
    }

    public FingardTransactionsDTO queryByPrimaryKey(String entNum, String id) {
        return fingardTransactionsMapper.selectByPrimaryKey(entNum,id);
    }

    public void insert(FingardTransactionsPO fingardTransactionsPO) {
        int i = fingardTransactionsMapper.insertSelective(fingardTransactionsPO.getEnterpriseCode(), fingardTransactionsPO);
        if (i != 1) {
            throw new MspDbException();
        }
    }

    public void update(FingardTransactionsPO fingardTransactionsPO) {
        int i = fingardTransactionsMapper.updateByPrimaryKeySelective(fingardTransactionsPO.getEnterpriseCode(), fingardTransactionsPO);
        if (i != 1) {
            throw new MspDbException();
        }
    }

    public Integer deleteOne(String entNum, String id) {
        return fingardTransactionsMapper.deleteByPrimaryKey(entNum, id);
    }

    public Integer deleteInBatches(String entNum, List<String> idList) {
        return fingardTransactionsMapper.deleteByPrimaryKeys(entNum, idList);
    }

    public PageInfo<FingardTransactionsDTO> listByParam(FingardTransactionsParam fingardTransactionsParam){
        PageHelper.startPage(fingardTransactionsParam.getPageNum(), fingardTransactionsParam.getPageSize(), fingardTransactionsParam.getOrderBy());
        return new PageInfo<>(fingardTransactionsMapper.listByParam(fingardTransactionsParam));
    }

    public CountsDTO countByParam(FingardTransactionsParam fingardTransactionsParam){
        return fingardTransactionsMapper.countByParam(fingardTransactionsParam);
    }
}